package a10_动态规划;

import java.util.Arrays;

/**
 * <p>
 * a19_零钱兑换2
 * </p>
 *
 * @author flyduck
 * @since 2025/2/13
 */
public class a19_零钱兑换2 {
    public static void main(String[] args) {
        int i = change(5, new int[]{1, 2, 5});
    }

    //物品0 1, 1, 1, 1, 1, 1
    //物品1 1, 1, 2, 2, 3, 3
    //物品2 1, 1, 2, 2, 3, 4
    public static int change(int amount, int[] coins) {
        int[] dp = new int[amount+1];
        dp[0] = 1;//因为递推公式是累加，如果是0得到的值肯定都是0了
        for (int i = 0; i < coins.length; i++) {
            for (int j = coins[i]; j <= amount; j++) {
                dp[j] = dp[j] + dp[j-coins[i]];
            }
            System.out.println(Arrays.toString(dp));
        }
        return dp[amount];
    }

}
